<template>
	<view class="home-page-c">
		<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			:duration="duration">
			<swiper-item v-for="i,index in urls" :key="index">
				<view class="swiper-item uni-bg-red">
					<img :src="i" alt="" mode="">
				</view>
			</swiper-item>
		</swiper>

		<view class="">
			<u-grid :border="false" col="5">
				<u-grid-item v-for="(listItem,listIndex) in gridItems" :key="listIndex" @click="gridClick"
					customStyle="padding-top: 4px; padding-bottom: 4px">
					<u-icon :customStyle="{paddingTop:20+'rpx'}" :name="listItem.name" :size="32"></u-icon>
					<text class="grid-text">{{listItem.title}}</text>
				</u-grid-item>
			</u-grid>
		</view>

		<u-sticky bgColor="#fff">
			<u-tabs :list="tabItems" @click="tabClick"></u-tabs>
		</u-sticky>

		<view class="goods-list">
			<view class="product-list">
				<view class="product" v-for="product in productList" :key="product.goods_id" @tap="toGoods(product)">
					<image mode="widthFix" :src="product.img"></image>
					<view class="name">{{ product.name }}</view>
					<view class="info">
						<view class="price">{{ product.price }}</view>
						<view class="slogan">{{ product.slogan }}</view>
					</view>
				</view>
			</view>
		</view>
    
    <u-gap height="120" bgColor="#f9f9f9"></u-gap>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				urls: [
					'/static/images/swiper/1.jpg',
					'/static/images/swiper/2.jpg',
					'/static/images/swiper/3.jpg',
				],
				gridItems: [{
						name: 'car',
						title: '图片'
					},
					{
						name: 'bell',
						title: '图片'
					},
					{
						name: 'bag',
						title: '图片'
					},
					{
						name: 'qzone',
						title: '图片'
					},
					{
						name: 'gift',
						title: '图片'
					}
				],
				tabItems: [{
						name: '关注',
					},
					{
						name: '推荐',
					},
					{
						name: '电影'
					},
					{
						name: '科技'
					},
					{
						name: '音乐'
					},
					{
						name: '美食'
					},
					{
						name: '文化'
					},
					{
						name: '财经'
					},
					{
						name: '手工'
					}
				],
				productList: [{
						goods_id: 0,
						img: '/static/img/goods/p1.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 1,
						img: '/static/img/goods/p2.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 2,
						img: '/static/img/goods/p3.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 3,
						img: '/static/img/goods/p4.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 4,
						img: '/static/img/goods/p5.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 5,
						img: '/static/img/goods/p6.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 6,
						img: '/static/img/goods/p7.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 7,
						img: '/static/img/goods/p8.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 8,
						img: '/static/img/goods/p9.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					},
					{
						goods_id: 9,
						img: '/static/img/goods/p10.jpg',
						name: '商品名称商品名称商品名称商品名称商品名称',
						price: '￥168',
						slogan: '1235人付款'
					}
				],
				loadingText: '正在加载...'
			}
		},
		onLoad() {

		},
		methods: {
			gridClick(name) {
				this.toCategory({id:name, name:name})
			},
			tabClick(item) {
				console.log(item);
			},
      //分类跳转
      toCategory(e) {
      	uni.navigateTo({
      		url: '/subpackages/goods-list/goods-list?cid='+e.id+'&name='+e.name
      	});
      },
      //商品跳转
      toGoods(e) {
      	uni.showToast({ title: '商品' + e.goods_id, icon: 'none' });
      	uni.navigateTo({
      		url: '/subpackages/goods/goods'
      	});
      },
		}
	}
</script>

<style lang="scss" scoped>
	.grid-text {
		font-size: 14px;
		color: #909399;
		padding: 10rpx 0 20rpx 0rpx;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}

	.goods-list {
		// background-color: #f4f4f4;
		.title {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			color: #f47825;
			font-size: 30upx;
			margin-top: 10upx;

			image {
				width: 30upx;
				height: 30upx;
			}
		}

		.loading-text {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60upx;
			color: #979797;
			font-size: 24upx;
		}

		.product-list {
			width: 92%;
			padding: 0 4% 3vw 4%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.product {
				width: 48%;
				border-radius: 20upx;
				background-color: #fff;
				margin: 0 0 15upx 0;
				box-shadow: 0upx 5upx 25upx rgba(0, 0, 0, 0.1);

				image {
					width: 100%;
					border-radius: 20upx 20upx 0 0;
				}

				.name {
					width: 92%;
					padding: 10upx 4%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					text-align: justify;
					overflow: hidden;
					font-size: 30upx;
				}

				.info {
					display: flex;
					justify-content: space-between;
					align-items: flex-end;
					width: 92%;
					padding: 10upx 4% 10upx 4%;

					.price {
						color: #e65339;
						font-size: 30upx;
						font-weight: 600;
					}

					.slogan {
						color: #807c87;
						font-size: 24upx;
					}
				}
			}
		}
	}
</style>